﻿<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>工作日报</title>
    <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no" />
    <link href="../Frozenui1.3/css/frozen.css" rel="stylesheet" />
    <script src="../JS/layer/layer.m.js"></script>
    <script src="../JS/zepto.min.js"></script>
    <script src="../Frozenui1.3/js/frozen.js"></script>
    <script src="../JS/MobileCom.js"></script>
    <script src="../JS/avalon.mobile.min.js"></script>
    <style type="text/css">
        .ui-tab-content {
            margin-top: 0px;
        }

        .ui-border {
            padding: 10px;
        }

        .ui-list > li {
            margin: 3px;
        }

        .ui-border {
            background-color: #fff;
        }

            .ui-border .v {
                border-top: solid 1px #ede8e8;
                padding: 5px;
                margin-top: 10px;
                font-size: 12px;
            }

                .ui-border .v span {
                    font-size: 10px;
                    float: right;
                }

        .ui-label-s {
            margin-right: 5px;
        }

        .ms-controller, [ms-controller] {
            display: none;
        }

        .pullDown, .pullUp {
            background: #fff;
            height: 40px;
            line-height: 40px;
            padding: 5px 10px;
            border-bottom: 1px solid #ccc;
            font-weight: bold;
            font-size: 14px;
            color: #888;
        }

        .pullDownIcon, #pullUp .pullUpIcon {
            display: block;
            float: left;
            width: 40px;
            height: 40px;
            background: url(../Images/pull-icon@2x.png) 0 0 no-repeat;
            -webkit-background-size: 40px 80px;
            background-size: 40px 80px;
            -webkit-transition-property: -webkit-transform;
            -webkit-transition-duration: 250ms;
        }

        .pullDownIcon {
            -webkit-transform: rotate(0deg) translateZ(0);
        }

        .pullUpIcon {
            -webkit-transform: rotate(-180deg) translateZ(0);
        }

        .flip .pullDownIcon {
            -webkit-transform: rotate(-180deg) translateZ(0);
        }

        .flip .pullUpIcon {
            -webkit-transform: rotate(0deg) translateZ(0);
        }

        .loading .pullDownIcon {
            background-position: 0 100%;
            -webkit-transform: rotate(0deg) translateZ(0);
            -webkit-transition-duration: 0ms;
            -webkit-animation-name: loading;
            -webkit-animation-duration: 2s;
            -webkit-animation-iteration-count: infinite;
            -webkit-animation-timing-function: linear;
        }

        @-webkit-keyframes loading {
            from {
                -webkit-transform: rotate(0deg) translateZ(0);
            }

            to {
                -webkit-transform: rotate(360deg) translateZ(0);
            }
        }
        .ms-controller, [ms-controller] {
            display: none;
        }
    </style>
</head>
<body>
    <div class="ui-footer ui-footer-stable ui-btn-group ui-border-t">
        <button  class="ui-btn-lg" onclick="back()">
            返回
        </button>
        <button class="ui-btn-lg ui-btn-primary" onclick="adddata()">
            新增报告
        </button>
    </div>
    <section>
        <div class="ui-tab">
            <ul class="ui-tab-nav ui-border-b">
                <li class="current">我的报告</li>
                <li>部门报告</li>
            </ul>
            <ul class="ui-tab-content" style="width:200%">
                <li style="height:auto">
                    <ul class="ui-list ui-list-pure" style="background-color:#f6f0f0;" ms-controller="rblist">
                        <li class="ui-border ui-label-list" ms-repeat-el="ctData">
                            <a class="ui-list-info" href="#" ms-click="vieww(el)">
                                <p><span class="ui-txt-info"> <label class="ui-label-s">{{el.LeiBie}}</label> {{el.CRUserName}} {{el.RBDate|date("yyyy-MM-dd")}}</span></p>
                                <p class="ui-txt-justify" style="overflow: hidden; word-wrap: break-word;">{{MobileCom.convstr (el.RBContent,40)}}</p>
                            </a>
                            <p class="v" style="margin-top:0">
                                <a href="#" ms-click="sc(el)" style="float:right;">
                                    <img src="../Images/delete.png" style="width:20px;height:20px" /><span style="color:black">删除</span>
                                </a>
                                <a href="#" ms-click="bj(el)" style="float:right;margin-right:10px">
                                    <img src="../Images/edit.png" style="width:20px;height:20px" /><span style="color:black">编辑</span>
                                </a>

                                <div style="clear: both"></div>
                            </p>
                        </li>
                    </ul>
                    <div id="rbpullDown" class="pullDown loading">
                        <span class="pullDownIcon"></span><span class="pullDownLabel">数据加载中...</span>
                    </div>
                </li>
                <li style="height:0">
                    <ul class="ui-list ui-list-pure" style="background-color:#f6f0f0;" ms-controller="bmrblist">
                        <li class="ui-border ui-label-list" ms-repeat-el="ctData">
                            <a class="ui-list-info" href="#" ms-click="vieww(el)">
                                <p><span class="ui-txt-info"> <label class="ui-label-s">{{el.LeiBie}}</label> {{el.CRUserName}} {{el.RBDate|date("yyyy-MM-dd")}}</span></p>
                                <p class="ui-txt-justify" style="overflow: hidden; word-wrap: break-word;">{{MobileCom.convstr (el.RBContent,40)}}</p>
                            </a>
                            <!--<p class="v" style="margin-top:0">
                                <a href="#" ms-click="sc(el)" style="float:right;">
                                    <img src="../Images/delete.png" style="width:20px;height:20px" /><span style="color:black">删除</span>
                                </a>
                                <a href="#" ms-click="bj(el)" style="float:right;margin-right:10px">
                                    <img src="../Images/edit.png" style="width:20px;height:20px" /><span style="color:black">编辑</span>
                                </a>

                                <div style="clear: both"></div>
                            </p>-->
                        </li>
                    </ul>
                    <div id="bmrbpullDown" class="pullDown loading">
                        <span class="pullDownIcon"></span><span class="pullDownLabel">数据加载中...</span>
                    </div>
                </li>
            </ul>
        </div>
    </section>
    <script>
        document.addEventListener('WeixinJSBridgeReady', function onBridgeReady() {
            //隐藏右上角按钮
            WeixinJSBridge.call('hideOptionMenu');
        });

        window.addEventListener('load', function () {

            var tab = new fz.Scroll('.ui-tab', {
                role: 'tab'
            });

            /* 滑动开始前 */
            tab.on('beforeScrollStart', function (from, to) {
                // from 为当前页，to 为下一页
            })

            /* 滑动结束 */
            tab.on('scrollEnd', function (curPage) {
                // curPage 当前页
            });

        })

        window.localStorage.removeItem("page1");
        window.localStorage.setItem("page1", 1);
        window.localStorage.removeItem("page2");
        window.localStorage.setItem("page2", 1);

        window.localStorage.removeItem("isjz1");
        window.localStorage.setItem("isjz1", 0);
        window.localStorage.removeItem("isjz2");
        window.localStorage.setItem("isjz2", 0);

        //if (MobileCom.getCookie("szhlcode") == null) {
        //    MobileCom.setCookie("szhlcode", "f2f69b36-359f-4877-abc2-6e07bf01d094", 7);
        //}

        var model = avalon.define({
            $id: "rblist",
            ctData: [],
            vieww: function (el) {
                window.location = "UI_GZRB_INFO.html?id=" + el.ID+"&r=" + Math.random();
            },
            bj: function (bjel) {
                window.location = "UI_GZRB_INPUT.html?ID=" + bjel.ID + "&r=" + Math.random();
            },
            sc: function (scel) {
                var tc = layer.open({
                    content: '确定要删除此日报吗？',
                    btn: ['确定', '取消'],
                    shadeClose: false,
                    yes: function () {
                        layer.close(tc);
                        var lg = $.loading({
                            content: '删除中...',
                        })
                        $.getJSON('/API/WXAPI.ashx?Action=DELGZRZBYID&r=' + Math.random(), { P1: scel.ID }, function (resultData) {
                            lg.hide();
                            if (resultData.ErrorMsg == "") {
                                model.ctData.remove(scel);
                                delitem(bmmodel.ctData, "ID", scel.ID);
                                var ts = $.tips({
                                    content: "删除成功",
                                    stayTime: 2000,
                                    type: "success"
                                })
                                ts.on("tips:hide", function () {
                                    //window.location.reload();
                                })
                            }
                            else {
                                $.tips({
                                    content: "删除失败，原因：" + resultData.ErrorMsg,
                                    stayTime: 2000,
                                    type: "warn"
                                })
                            }
                        })
                    }, no: function () {
                    }
                })
            }
        });

        var bmmodel = avalon.define({
            $id: "bmrblist",
            ctData: [],
            queryusers:"",
            vieww: function (el) {
                window.location = "UI_GZRB_INFO.html?id=" + el.ID + "&r=" + Math.random();
            }

        });

        $(window).scroll(function () {

            if ($(document).height() - $(this).scrollTop() - $(this).height() < 40) {
                loadMore();
            }

        })

        function rb() {
            var isjz1 = window.localStorage.getItem("isjz1");
            if (isjz1 == 0) {
                window.localStorage.setItem("isjz1", 1);
                var page = window.localStorage.getItem("page1");
                $.getJSON("/API/WXAPI.ashx?Action=GETGZRZLIST&p=" + page+"&r="+Math.random(), {}, function (r) {
                    if (r.ErrorMsg == "") {
                        if (r.Result.length > 0) {
                            model.ctData.pushArray(r.Result);
                            if (r.Result.length < 8) {
                                window.localStorage.setItem("page1", 0);
                                $("#rbpullDown").find(".pullDownLabel").text("已加载所有数据");
                                $("#rbpullDown").removeClass("loading");
                                $("#rbpullDown span").eq(0).hide();

                            }
                            else {
                                var page1 = window.localStorage.getItem("page1");
                                window.localStorage.setItem("page1", parseInt(page1) + 1);
                            }
                        } else {
                            var page = window.localStorage.getItem("page1");
                            if (page == "1") {
                                $("#rbpullDown").find(".pullDownLabel").text("没有数据");
                                $("#rbpullDown").removeClass("loading");
                                $("#rbpullDown span").eq(0).hide();
                            }
                            else {
                                window.localStorage.setItem("page1", 0);
                                $("#rbpullDown").find(".pullDownLabel").text("已加载所有数据");
                                $("#rbpullDown").removeClass("loading");
                                $("#rbpullDown span").eq(0).hide();
                            }
                        }

                    } else {

                    }
                    window.localStorage.setItem("isjz1",0);
                })
            }
        }

        function bmrb() {
            var isjz2 = window.localStorage.getItem("isjz2");
            if (isjz2 == 0) {
                window.localStorage.setItem("isjz2", 1);
                var page = window.localStorage.getItem("page2");

                $.getJSON("/API/WXAPI.ashx?Action=GETGZRZLIST&p=" + page + "&r=" + Math.random(), {"b":"-1", "QUSER": bmmodel.queryusers }, function (r) {
                    if (r.ErrorMsg == "") {
                        if (r.Result.length > 0) {
                            bmmodel.ctData.pushArray(r.Result);
                            if (r.Result.length < 8) {
                                window.localStorage.setItem("page2", 0);
                                $("#bmrbpullDown").find(".pullDownLabel").text("已加载所有数据");
                                $("#bmrbpullDown").removeClass("loading");
                                $("#bmrbpullDown span").eq(0).hide();

                            }
                            else {
                                var page2 = window.localStorage.getItem("page2");
                                window.localStorage.setItem("page2", parseInt(page2) + 1);
                            }
                        } else {
                            var page = window.localStorage.getItem("page2");
                            if (page == "1") {
                                $("#bmrbpullDown").find(".pullDownLabel").text("没有数据");
                                $("#bmrbpullDown").removeClass("loading");
                                $("#bmrbpullDown span").eq(0).hide();
                            }
                            else {
                                window.localStorage.setItem("page2", 0);
                                $("#bmrbpullDown").find(".pullDownLabel").text("已加载所有数据");
                                $("#bmrbpullDown").removeClass("loading");
                                $("#bmrbpullDown span").eq(0).hide();
                            }
                        }

                    } else {

                    }
                    window.localStorage.setItem("isjz2", 0);
                })

            }
        }

        function loadMore() {

            if ($(".ui-tab-nav li").eq(0).hasClass("current")) {
                var page = window.localStorage.getItem("page1");
                if (page != "0") {
                    rb();
                }
            }
            else {
                var page = window.localStorage.getItem("page2");
                if (page != "0") {
                    bmrb();
                }
            }
        }

        function delitem(items, delkey, delval) {
            for (i = items.length - 1; i >= 0; i--) {
                if (items[i][delkey] == delval) {
                    items.splice(i, 1)
                }
            }
        }
        avalon.ready(function () {
            rb();
            $.getJSON('/API/SZHLAPI.ashx?Action=GETQUERYUSER', { P1: "1" }, function (resultData) {
                if (resultData.ErrorMsg == "") {
                    bmmodel.queryusers = resultData.Result ? resultData.Result : "-1";
                    bmrb();
                }
            })
        })

        function back() {
            window.location.replace("UI_BASE_PAGE.html?r=" + Math.random());
        }
        function adddata() {
            window.location = "UI_GZRB_INPUT.html?r=" + Math.random();
        }
    </script>
</body>
</html>
